WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
capture_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Forward declarations for node templates
22namespace wolf
23{
24class FrameBase;
25class FeatureBase;
26} // namespace wolf
27
28// Wolf includes
29#include "core/common/wolf.h"
32
33// std includes
34
35namespace wolf
36{
37// class CaptureBase
39{
40 friend class FeatureBase;
41 friend class FactorBase;
42 friend class FrameBase;
43
44 private:
45 FrameBaseWPtr frame_ptr_;
46 FeatureBasePtrList feature_list_;
47 SensorBaseWPtr sensor_ptr_;
48
49 static unsigned int capture_id_count_;
50
51 protected:
52 unsigned int capture_id_;
54 void setProblem(ProblemPtr _problem) override final;
55
56 public:
72 CaptureBase(const std::string& _type,
73 const TimeStamp& _ts,
74 SensorBasePtr _sensor_ptr = nullptr,
75 const TypeComposite& _state_types = {},
76 const VectorComposite& _state_vectors = {},
77 const PriorComposite& _state_priors = {});
78
79 ~CaptureBase() override = default;
80
85 void remove(bool viral_remove_parent_without_children = false) override;
86
91 bool hasChildren() const override;
92
100 virtual FactorBasePtr emplaceDriftFactor(CaptureBasePtr _capture_origin, char _key, bool _apply_loss_function);
101
107 virtual bool isMotion() const;
108
113 bool process();
114
115 unsigned int id() const override;
116 TimeStamp getTimeStamp() const;
117 void setTimeStamp(const TimeStamp& _ts);
118 void setTimeStampToNow();
119
120 FrameBaseConstPtr getFrame() const;
121 FrameBasePtr getFrame();
122
123 private:
124 void setFrame(const FrameBasePtr _frm_ptr);
125
126 public:
127 FeatureBaseConstPtrList getFeatureList() const;
128 FeatureBasePtrList getFeatureList();
129 bool hasFeature(const FeatureBaseConstPtr& _feature) const;
130
131 FactorBaseConstPtrList getFactorList() const;
132 FactorBasePtrList getFactorList();
133 void getFactorList(FactorBaseConstPtrList& _fac_list) const;
134 void getFactorList(FactorBasePtrList& _fac_list);
135
136 SensorBaseConstPtr getSensor() const;
137 SensorBasePtr getSensor();
138 virtual void setSensor(const SensorBasePtr sensor_ptr);
139
140 public:
141 // State blocks
142 StateBlockConstPtr getStateBlock(const char& _key) const override;
143 StateBlockPtr getStateBlock(const char& _key) override;
144 StateBlockConstPtr getSensorP() const;
145 StateBlockPtr getSensorP();
146 StateBlockConstPtr getSensorO() const;
147 StateBlockPtr getSensorO();
148 StateBlockConstPtr getSensorIntrinsic() const;
149 StateBlockPtr getSensorIntrinsic();
150
151 void fix() override;
152 void unfix() override;
153
158 void link(FrameBasePtr _frm_ptr);
159
166 template <typename classType, typename... T>
167 static std::shared_ptr<classType> emplace(FrameBasePtr _frm_ptr, T&&... all);
168
178 virtual void printHeader(int depth,
179 bool factored_by,
180 bool metric,
181 bool state_blocks,
182 std::ostream& stream,
183 std::string _tabs = "") const;
184
194 void print(int depth,
195 bool factored_by,
196 bool metric,
197 bool state_blocks,
198 std::ostream& stream = std::cout,
199 std::string _tabs = "") const;
200
208 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
209
218 bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
219
220 private:
221 FeatureBasePtr addFeature(FeatureBasePtr _ft_ptr);
222 void removeFeature(FeatureBasePtr _ft_ptr);
223
224 public:
225 CaptureBasePtr shared_from_this_capture();
226 CaptureBaseConstPtr shared_from_this_capture() const;
227};
228
229} // namespace wolf
230
235
236namespace wolf
237{
238inline bool CaptureBase::isMotion() const
239{
240 return false;
241}
242
243template <typename classType, typename... T>
244std::shared_ptr<classType> CaptureBase::emplace(FrameBasePtr _frm_ptr, T&&... all)
245{
246 std::shared_ptr<classType> cpt = std::make_shared<classType>(std::forward<T>(all)...);
247 cpt->emplacePriors();
248 cpt->link(_frm_ptr);
249 return cpt;
250}
251
252inline StateBlockConstPtr CaptureBase::getSensorP() const
253{
254 return getStateBlock('P');
255}
256
257inline StateBlockPtr CaptureBase::getSensorP()
258{
259 return getStateBlock('P');
260}
261
262inline StateBlockConstPtr CaptureBase::getSensorO() const
263{
264 return getStateBlock('O');
265}
266
267inline StateBlockPtr CaptureBase::getSensorO()
268{
269 return getStateBlock('O');
270}
271
272inline StateBlockConstPtr CaptureBase::getSensorIntrinsic() const
273{
274 return getStateBlock('I');
275}
276
278{
279 return getStateBlock('I');
280}
281
282inline unsigned int CaptureBase::id() const
283{
284 return capture_id_;
285}
286
287inline FrameBaseConstPtr CaptureBase::getFrame() const
288{
289 if (frame_ptr_.expired())
290 return nullptr;
291 else
292 return frame_ptr_.lock();
293}
294
295inline FrameBasePtr CaptureBase::getFrame()
296{
297 if (frame_ptr_.expired())
298 return nullptr;
299 else
300 return frame_ptr_.lock();
301}
302
303inline void CaptureBase::setFrame(const FrameBasePtr _frm_ptr)
304{
305 frame_ptr_ = _frm_ptr;
306}
307
308inline FeatureBaseConstPtrList CaptureBase::getFeatureList() const
309{
310 FeatureBaseConstPtrList list_const;
311 for (auto&& obj_ptr : feature_list_) list_const.push_back(obj_ptr);
312 return list_const;
313}
314
315inline FeatureBasePtrList CaptureBase::getFeatureList()
316{
317 return feature_list_;
318}
319
321{
322 return time_stamp_;
323}
324
325inline SensorBaseConstPtr CaptureBase::getSensor() const
326{
327 return sensor_ptr_.lock();
328}
329
330inline SensorBasePtr CaptureBase::getSensor()
331{
332 return sensor_ptr_.lock();
333}
334
335inline void CaptureBase::setSensor(const SensorBasePtr sensor_ptr)
336{
337 sensor_ptr_ = sensor_ptr;
338}
339
341{
342 time_stamp_ = _ts;
343}
344
346{
348}
349
351{
352 return std::static_pointer_cast<CaptureBase>(shared_from_this());
353}
354
355inline CaptureBaseConstPtr CaptureBase::shared_from_this_capture() const
356{
357 return std::static_pointer_cast<const CaptureBase>(shared_from_this());
358}
359
360} // namespace wolf
Definition: capture_base.h:39
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Print the header information of the capture.
Definition: capture_base.cpp:268
bool process()
Process the capture.
Definition: capture_base.cpp:151
StateBlockConstPtr getSensorO() const
Definition: capture_base.h:262
unsigned int id() const override
Definition: capture_base.h:282
TimeStamp time_stamp_
Time stamp.
Definition: capture_base.h:53
StateBlockConstPtr getSensorP() const
Definition: capture_base.h:252
void fix() override
Definition: capture_base.cpp:227
void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Print the capture details.
Definition: capture_base.cpp:296
FrameBaseConstPtr getFrame() const
Definition: capture_base.h:287
StateBlockConstPtr getStateBlock(const char &_key) const override
Definition: capture_base.cpp:201
FeatureBaseConstPtrList getFeatureList() const
Definition: capture_base.h:308
unsigned int capture_id_
Definition: capture_base.h:52
CaptureBase(const std::string &_type, const TimeStamp &_ts, SensorBasePtr _sensor_ptr=nullptr, const TypeComposite &_state_types={}, const VectorComposite &_state_vectors={}, const PriorComposite &_state_priors={})
Constructor.
Definition: capture_base.cpp:29
SensorBaseConstPtr getSensor() const
Definition: capture_base.h:325
void setTimeStamp(const TimeStamp &_ts)
Definition: capture_base.h:340
bool hasChildren() const override
Check if the capture has any children.
Definition: capture_base.cpp:109
void setProblem(ProblemPtr _problem) override final
Definition: capture_base.cpp:252
FactorBaseConstPtrList getFactorList() const
Definition: capture_base.cpp:170
virtual FactorBasePtr emplaceDriftFactor(CaptureBasePtr _capture_origin, char _key, bool _apply_loss_function)
Emplace a FactorBlockDifference with zero difference between the state _key of this capture and _capt...
Definition: capture_base.cpp:114
virtual void setSensor(const SensorBasePtr sensor_ptr)
Definition: capture_base.h:335
void unfix() override
Definition: capture_base.cpp:232
StateBlockConstPtr getSensorIntrinsic() const
Definition: capture_base.h:272
virtual bool isMotion() const
Is a motion if there is motion detected.
Definition: capture_base.h:238
void link(FrameBasePtr _frm_ptr)
Link the capture to a frame.
Definition: capture_base.cpp:237
~CaptureBase() override=default
void remove(bool viral_remove_parent_without_children=false) override
Remove the capture.
Definition: capture_base.cpp:73
bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Check the capture.
Definition: capture_base.cpp:378
CaptureBasePtr shared_from_this_capture()
Definition: capture_base.h:350
void setTimeStampToNow()
Definition: capture_base.h:345
TimeStamp getTimeStamp() const
Definition: capture_base.h:320
bool hasFeature(const FeatureBaseConstPtr &_feature) const
Definition: capture_base.cpp:196
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Perform a local check on the capture.
Definition: capture_base.cpp:309
static std::shared_ptr< classType > emplace(FrameBasePtr _frm_ptr, T &&... all)
Emplace a new capture of type classType.
Definition: capture_base.h:244
Definition: check_log.h:28
Definition: factor_base.h:72
Definition: feature_base.h:38
Definition: frame_base.h:38
Definition: node_state_blocks.h:32
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
void setToNow()
Time stamp to now.
Definition: time_stamp.cpp:69
Definition: vector_composite.h:27
Definition: capture_base.h:23
Composite< Prior > PriorComposite
Definition: prior_composite.h:56